package com.cjm.algorithm.leetcode;

import com.cjm.algorithm.TreeNode;

public class CountNodes222 {
    public static int countNodes(TreeNode root) {
        return count(root);
    }

    private static int count(TreeNode root) {
        if (root == null) return 0;
        int count = count(root.left);
        int count1 = count(root.right);
        return count + count1 + 1;
    }

    public static void main(String[] args) {
        System.err.println(countNodes(TreeNode.generatorTreeNode(new Integer[]{1,2,3,4,5,6})));
        System.err.println(countNodes(TreeNode.generatorTreeNode(new Integer[]{1})));
        System.err.println(countNodes(TreeNode.generatorTreeNode(new Integer[]{})));
    }
}
